const fs = require('fs');
const readline = require('readline');

// 创建读取文件流
const fileStream = fs.createReadStream('./log.txt');

// 创建逐行读取的接口
const rl = readline.createInterface({
    input: fileStream,
    crlfDelay: Infinity
});

// 定义正则表达式匹配模式
const pattern = /POST\s(.*?)\sHTTP\/1.1/;
const fieldCount = {};

// 逐行处理日志文件
rl.on('line', (line) => {
    const match = line.match(pattern);
    if (match) {
        const field = match[1];
        if (fieldCount[field]) {
            fieldCount[field]++;
        } else {
            fieldCount[field] = 1;
        }
    }
});

rl.on('close', () => {
    console.log('File processing completed.');
    console.log('Fields with more than 5 occurrences:');

    // 筛选出出现次数大于5的字段
    for (const [field, count] of Object.entries(fieldCount)) {
        if (count > 5) {
            console.log(`${field}: ${count} times`);
        }
    }
});
